package demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 演示使用配置文件中的参数（方式一，使用全局Environment对象访问参数）
 * 注意需引入Environment（容器自带）
 */
@RestController
public class ControllerToTestProperties {
    final Environment environment;

    @Autowired
    public ControllerToTestProperties(Environment environment){
        this.environment = environment;
    }

    @RequestMapping("/testProperties")
    public String getParams(){
        return "db.username:  " + environment.getProperty("db.username");
    }

}
